﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.Core.Exceptions;
using Enterprise.Framework.DomainModel.Repositories;

namespace Resto.CostControl.Core.Domain.Query.SiteModule
{
    internal class SiteDQO : IDomainQueryObject
    {
        public Site GetSite(string id)
        {
            Site order = GetSiteOrDefault(id);

            if (order == null)
                throw new BusinessException("指定Id的项目点不存在");

            return order;
        }

        public Site GetSiteOrDefault(string id)
        {
            IEntityRepository<Site> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Site>();
            Site order = repository.Objects.Where(p => p.ID == id).FirstOrDefault();

            return order;
        }

        public string[] GetAllSiteId()
        {
            IEntityRepository<Site> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<Site>();
            var list = from o in repository.Objects
                       where o.IsDelete == false
                       select o.ID;

            return list.ToArray();
        }
    }
}
